package com.hfzy.ihk.web.aliyun.forward;

import com.google.common.collect.Lists;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by Administrator on 2018/7/31.
 *
 * @author wws
 */
@Configuration
@SpringBootApplication
@RestController
public class Application {

    private static List<String> aliyunServerList = Lists.newArrayList("rmi://172.16.6.111:60000/xxxxService","rmi://172.16.6.222:60000/xxxxService");


    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }


    @RequestMapping("/aliyunMessage")
    public void forwardHttp4Message(HttpServletRequest request, HttpServletResponse response){

    }

    @RequestMapping("/aliyunText")
    public void forwardHttp4Text(HttpServletRequest request, HttpServletResponse response){

    }

    /**
     *
     * 根据sessionId取哈希值路由至某一服务
     * */
    private String getTargetServer(String sessionId){

        int index = 0;

        index = sessionId.hashCode()%aliyunServerList.size();

        return aliyunServerList.get(index);
    }
}
